package org.hot100_1;

public class leetcode64 {
    class MinStack{
        class Node{
            //min属性表示没有加入当前节点前的栈中最小值
            int min;
            int val;
            Node next;

            Node (){
                this.min=Integer.MAX_VALUE;
            }

            Node (int val){
               this.val=val;
            }

        }

        Node dummy;

        MinStack(){
            this.dummy = new Node();
        }

        void push(int val){
            Node node = new Node(val);
            node.next=dummy.next;
            node.min= dummy.min;

            dummy.next=node;
            dummy.min= Math.min(val,dummy.min);
        }

        void pop(){
            Node curr = dummy.next;
            if (dummy.min==curr.val){
                dummy.min= curr.min;
            }
            dummy.next=curr.next;
            curr.next=null;
        }

        int top(){
            return dummy.next.val;
        }

        int getMin(){
            return dummy.min;
        }
    }

}
